package com.example.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class RedisController {

    //1.引入redis模板
    @Autowired
    private StringRedisTemplate stringRedisTemplate;


    @RequestMapping("/set")
    public String set() {
        stringRedisTemplate.opsForValue().set("username","lisi");
        return "redis 存储成功";
    }

    @RequestMapping("/get")
    public String get() {
        return stringRedisTemplate.opsForValue().get("username");
    }
}
